package com.hang.gymmanager.common;

/**
 * 返回响应类
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/3/15 16:46
 */
    public class Response<T> {

        /**
         * 状态码
         */
        private String code;

        /**
         * 信息
         */
        private String message;

        /**
         * 数据
         */
        private T data;

        /**
         * 成功返回体(带参)
         * @param data
         * @return
         */
        public static <T> Response<T> success(T data){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.SUCCESS.getCode());
            result.setMessage(ResponseEnum.SUCCESS.getMessage());
            result.setData(data);
            return result;
        }

        /**
         * 成功返回体(不带参)
         * @return
         */
        public static <T> Response<T> success(){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.SUCCESS.getCode());
            result.setMessage(ResponseEnum.SUCCESS.getMessage());
            return result;
        }

        /**
         * 代码错误返回体(带参)
         * @param data
         * @return
         */
        public static <T> Response<T> serverError(T data){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.SERVER_INNER_ERROR.getCode());
            result.setMessage(ResponseEnum.SERVER_INNER_ERROR.getMessage());
            result.setData(data);
            return result;
        }

        /**
         * 代码错误返回体(不带参)
         * @return
         */
        public static <T> Response<T> serverError(){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.SERVER_INNER_ERROR.getCode());
            result.setMessage(ResponseEnum.SERVER_INNER_ERROR.getMessage());
            return result;
        }

        /**
         * 数据库操作失败返回体(带参)
         * @param data
         * @return
         */
        public static <T> Response<T> operationError(T data){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.OPERATION_FAILED.getCode());
            result.setMessage(ResponseEnum.OPERATION_FAILED.getMessage());
            result.setData(data);
            return result;
        }

        /**
         * 数据库操作失败返回体(不带参)
         * @return
         */
        public static <T> Response<T> operationError(){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.OPERATION_FAILED.getCode());
            result.setMessage(ResponseEnum.OPERATION_FAILED.getMessage());
            return result;
        }

        /**
         * 查找用户失败(带参)
         * @param data
         * @return
         */
        public static <T> Response<T> findUserFailed(T data){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.FIND_USER_FAILED.getCode());
            result.setMessage(ResponseEnum.FIND_USER_FAILED.getMessage());
            result.setData(data);
            return result;
        }

        /**
         * 数据库操作失败返回体(不带参)
         * @return
         */
        public static <T> Response<T> findUserFailed(){
            Response<T> result = new Response<>();
            result.setCode(ResponseEnum.FIND_USER_FAILED.getCode());
            result.setMessage(ResponseEnum.FIND_USER_FAILED.getMessage());
            return result;
        }

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }
}
